#'
#' get spatially overlapped individuals
#' 
#' @usage
#' get_overlapped(x,y)
#' get_overlapped(com)
#' get_overlapped(pop)
#'
#' @param x,y vectors of individual coordination
#' @param com a community object
#' @param pop a population object
#'
#' @return
#' A list of points with identical coordinations
#' 
#' @examples
#' data(BCI)
#' 
#' BCI  #please note the warning message
#' 
#' 
#' get_overlapped(BCI)
#'
#'@export
get_overlapped=function(x,...){
  UseMethod("get_overlapped")
}

get_overlapped.numeric=function(x,y){
  xy=paste(x,y,sep="")
  xyfreq=table(xy)
  invalid_i=which(xyfreq>1)
  if(length(invalid_i)==0){
    return(list())
  }else{
    invalid_xy=names(xyfreq)[invalid_i]
    ind_i=list()
    for(i in 1:length(invalid_xy)){
      ind_i[[i]]=which(xy==invalid_xy[i])
    }
    return(ind_i)
  }
}

get_overlapped.community=function(com){
  get_overlapped(com$x,com$y)
}

get_overlapped.population=function(pop){
  get_overlapped(pop$x,pop$y)
}
